package com.fanqwz.kotlinmvvm.ui.widget

import android.content.Context
import android.support.annotation.AttrRes
import android.util.AttributeSet
import android.view.KeyEvent
import android.view.MotionEvent
import android.widget.FrameLayout

/**
 * Created by fanqwz on 2017/8/7.
 */

class InterceptTouchFrameLayout : FrameLayout {
    constructor(context: Context) : super(context)

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs)

    constructor(context: Context, attrs: AttributeSet, @AttrRes defStyleAttr: Int) : super(context, attrs, defStyleAttr)

    public var interceptEvent: Boolean = false

    override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
        return if (interceptEvent) true
        else super.onInterceptTouchEvent(ev)
    }

    override fun dispatchKeyEvent(event: KeyEvent?): Boolean {
        return if (interceptEvent) true
        else super.dispatchKeyEvent(event)
    }

//    override fun onInterceptHoverEvent(event: MotionEvent): Boolean {
//        return if (interceptEvent) true
//        else super.onInterceptHoverEvent(event)
//    }

    override fun onTouchEvent(event: MotionEvent): Boolean {
        return if (interceptEvent) true
        else super.onTouchEvent(event)
    }
}
